package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfResourceBlacklist;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfResourceBlacklistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 服务资源黑名单配置表-Controller
 * @author zfsn
 * @date 2023-3-15
 */
@Api(tags = "业务服务资源管理-黑白名单配置-黑名单")
@RestController
@RequestMapping("/resourceBlacklist")
public class ConfResourceBlacklistController {

	@Autowired
	private ConfResourceBlacklistService confResourceBlacklistService;

	/**
	 * 通过主键查询数据
	 *
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfResourceBlacklist>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confResourceBlacklistService.listByIds(idList));
	}

	/**
	 * 分页查询
	 *
	 * @param confResourceBlacklist 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "类型", paramType = "query", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "key", value = "键", paramType = "query", required = false, dataType = "String"),
			@ApiImplicitParam(name = "value", value = "值", paramType = "query", required = false, dataType = "String"),
			@ApiImplicitParam(name = "isEnable", value = "是否启用", paramType = "query", required = false, dataTypeClass = Integer.class),
	})
	public R<Page<ConfResourceBlacklist>> listPage(@RequestBody ConfResourceBlacklist confResourceBlacklist) {
		return R.ok(confResourceBlacklistService.listPage(confResourceBlacklist));
	}

	/**
	 * 新增数据
	 *
	 * @param confResourceBlacklist 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增服务资源黑名单配置表数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "类型", paramType = "query", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "key", value = "键", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "value", value = "值", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isEnable", value = "是否启用", paramType = "query", required = true, dataTypeClass = Integer.class),
	})
	public R<Boolean> save(@RequestBody ConfResourceBlacklist confResourceBlacklist) {
		return R.ok(confResourceBlacklistService.save(confResourceBlacklist));
	}

	/**
	 * 通过主键更新数据
	 *
	 * @param confResourceBlacklist 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新服务资源黑名单配置表数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "type", value = "类型", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "key", value = "键", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "value", value = "值", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "isEnable", value = "是否启用", paramType = "body", required = false, dataTypeClass = Integer.class),
	})
	public R<Boolean> updateById(@RequestBody @ApiIgnore ConfResourceBlacklist confResourceBlacklist) {
		return R.ok(confResourceBlacklistService.updateById(confResourceBlacklist));
	}

}